/**
 * For detailed testing description, please refer to the developer's guide.
 * @author Yong Yao
 */
package logic;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

import logic.Parser;

import org.junit.Test;

public class ParserTest {
	@Test
	public void testParser() {
		testIsCommandWord();
		//testcheckAddParameters();
		//testcheckDeleteParameters();
		//testcheckDisplayParameters();
		testcheckEditParameters();
	}

	private void testIsCommandWord() {
		assertTrue(Parser.testIsCommandWord("add"));
		assertFalse(Parser.testIsCommandWord("adddd"));
	}

	private void testcheckEditParameters() {
		assertEquals("Test Case 1", "1 26/09/12 27/09/12 1700 1800 a proper task",
				Parser.outputEditParamters("1 bd 26/9/12 27/9/12 bt 5pm 6pm <a proper task>"));
		assertEquals("Test Case 2", "Please enter the parameters.", Parser.outputEditParamters(""));
	}

	private void testcheckDisplayParameters() {
		assertEquals("Test Case 1 - T,D,F,A", "a",
				Parser.outputDisplayParamters("a"));
		assertEquals("Test Case 2 - Range with Start and End",
				"r 26/09/12 27/09/12",
				Parser.outputDisplayParamters("r 26/9/12 27/9/12"));
		assertEquals("Test Case 3 - Range with End and Start",
				"r 26/09/12 27/09/12",
				Parser.outputDisplayParamters("R 27/9/12 26/9/12"));
		assertEquals("Test Case 4 - Range with Start only", "r 26/09/12",
				Parser.outputDisplayParamters("R 26/9/12"));
		assertEquals("Test Case 5 - Large gaps", "a",
				Parser.outputDisplayParamters("        a  "));
		assertEquals("Test Case 6 - Wrong Display Type",
				"wrong Error Display Type must be correct.",
				Parser.outputDisplayParamters("wrong"));
	}

	private void testcheckDeleteParameters() {
		assertEquals("Test Case 1 - Valid Integer", "1",
				Parser.outputDeleteParameters("1"));
		assertEquals("Test Case 2 - Invalid Integer",
				"-1 Error Delete must have valid row number.",
				Parser.outputDeleteParameters("1.23"));
		assertEquals("Test Case 3 - Negative Integer",
				"-1 Error Delete must have valid row number.",
				Parser.outputDeleteParameters("-1"));
		assertEquals("Test Case 4 - No Integer",
				"-1 Error Delete must have valid row number.",
				Parser.outputDeleteParameters(""));
		assertEquals("Test Case 5 - String",
				"-1 Error Delete must have valid row number.",
				Parser.outputDeleteParameters("one"));
		assertEquals("Test Case 6 - Character",
				"-1 Error Delete must have valid row number.",
				Parser.outputDeleteParameters("o"));
	}

	private void testcheckAddParameters() {
		assertEquals("Test Case 1 - All already correct",
				"25/06/12 1200 26/06/12 1300 ha ha",
				Parser.outputAddParameters("25/06/12 1200 26/06/12 1300 ha ha"));
		assertEquals("Test Case 2 - Start and End Opposite",
				"25/06/12 1200 26/06/12 1300 ha ha",
				Parser.outputAddParameters("26/06/12 1300 25/06/12 1200 ha ha"));
		assertEquals(
				"Test Case 3 - Start and End Opposite & Different Format",
				"25/06/12 1200 26/06/12 1300 ha ha",
				Parser.outputAddParameters("26/6/2012 25.6.2012 1pm 12:00pm ha ha"));
		assertEquals(
				"Test Case 4 - Mixed Order",
				"25/06/12 1200 26/06/12 1300 ha ha",
				Parser.outputAddParameters("1pm 26/6/2012 12:00pm ha ha 25.6.2012"));
		assertEquals(
				"Test Case 5 - Contains large gaps",
				"25/06/12 1200 26/06/12 1300 ha ha",
				Parser.outputAddParameters("1pm       26/6/2012        12:00pm       ha ha       25.6.2012"));
		assertEquals(
				"Test Case 6 - Task is separated",
				"25/06/12 1200 26/06/12 1300 ha ha",
				Parser.outputAddParameters("ha   1pm       26/6/2012        12:00pm        ha       25.6.2012"));
		assertEquals("Test Case 7 - Deadline Task", "25/06/12 1200 ha ha",
				Parser.outputAddParameters("25/6/12 12pm ha ha"));
	}
}
